from typing import List, Optional, Dict

# 绝对导入
from app.models.schemas import ModelInfo


class ModelManager:
    """
    Manager for AI models - handles model availability and information
    """

    def __init__(self):
        self.models: Dict[str, ModelInfo] = {
            "gpt-3.5-turbo": ModelInfo(
                name="gpt-3.5-turbo",
                description="Fast and cost-effective GPT-3.5 model suitable for most tasks",
                max_tokens=4096,
                is_available=True
            ),
            "gpt-4": ModelInfo(
                name="gpt-4",
                description="Advanced GPT-4 model with improved reasoning and capabilities",
                max_tokens=8192,
                is_available=True
            ),
            "claude-3-sonnet": ModelInfo(
                name="claude-3-sonnet",
                description="Anthropic's balanced model with strong reasoning skills",
                max_tokens=200000,
                is_available=True
            ),
            "llama-2-7b": ModelInfo(
                name="llama-2-7b",
                description="Open-source 7B parameter model from Meta",
                max_tokens=4096,
                is_available=True
            )
        }

        self.request_count = 0

    def get_available_models(self) -> List[ModelInfo]:
        """Get list of all available models"""
        return [model for model in self.models.values() if model.is_available]

    def get_model_info(self, model_name: str) -> Optional[ModelInfo]:
        """Get information about a specific model"""
        return self.models.get(model_name)

    def is_model_available(self, model_name: str) -> bool:
        """Check if a model is available"""
        model = self.models.get(model_name)
        return model is not None and model.is_available

    def get_active_models(self) -> List[str]:
        """Get list of active model names"""
        return [name for name, model in self.models.items() if model.is_available]

    def get_total_requests(self) -> int:
        """Get total number of requests processed"""
        return self.request_count

    def increment_request_count(self):
        """Increment request counter"""
        self.request_count += 1